﻿#Include ..\baseHandle.ahk

class Todo extends BaseHandle {
  static nullable := true

  static Handle(parsed) {
    _p := '.\cfg\todoFile.txt', cfs := MeowConfEx.Of(_p)
    if !(_t := parsed.target) {
      Run _p
      return this.Succ('ok', 'x')
    }
    if cfs.Has(_t) {
      if !parsed.extra.Length
        return this.Succ(cfs.Get(_t).join('`n'))
      for k in parsed.extra
        cfs.Append(_t, k)
      return (cfs.Sync(), this.Succ('appended!'))
    } else {
      if !parsed.extra.Length
        return this.Fail('val can not be null')
      cfs.Add(_t, parsed.extra)
      cfs.Sync()
      return this.Succ('created!')
    }
    return this.Fail('failed for unknown reason')
  }

 static Spec() {
    return {
      cmd: 'todo',
      desc: '添加或显示todos',
      format: 'todo [key] [val...]',
      args: {
        desc: '',
        isOptional: true,
        cacheable: true,
        generator: {
          script: '',
          postProcess: (*) => MeowConf.Of('./cfg/todoFile.txt').data.keys
        }
      },
      extra: {
        isEnable: true,
        isMulti: true,
        desc: '输入要添加的子项'
      }
    }
  }
}
